package com.example.common;

import lombok.Data;

import static com.example.common.Const.*;


/**
 * @Author zhangming
 * @Date 2021/7/9 9:10
 * @Version 1.0
 */
@Data
public class Rt<T>{

    /**
     * 成功标识 200成功 500失败
     */
    private int code;

    /**
     * 返回结果信息
     */
    protected String msg;

    /**
     * 结果数据
     */
    private T data;


    protected Rt() {
    }


    public static <T> Rt<T> fail() {
        return fail(FAIL, null);
    }

    public static <T> Rt<T> fail(String msg) {
        return fail(msg, null);
    }

    public static <T> Rt<T> fail(String msg, T data) {
        return create(FAIL_CODE, msg, data);
    }

    public static <T> Rt<T> success() {
        return success(SUCCESS, null);
    }

    public static <T> Rt<T> success(T data) {
        return success(SUCCESS, data);
    }

    public static <T> Rt<T> success(String msg, T data) {
        return create(SUCCESS_CODE, msg, data);
    }

    public static <T> Rt<T> create(int code, String msg, T data) {
        Rt<T> Rt = new Rt<>();
        Rt.setCode(code);
        Rt.setMsg(msg);
        Rt.setData(data);
        return Rt;
    }

}
